package level4.mo_ui.box
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import level4.display.GameDispose;

	/**
	 * 自制 简易HBox
	 * */
	public class HBox extends GameDispose
	{
		public var hgap:int = 2;
		public function HBox()
		{
			
		}
		override protected function init(e:Event):void{
		}
		override protected function deInit(e:Event):void{
			
		}
		override public function addChild(child:DisplayObject):DisplayObject{
			var hdist:int=0;
			for(var i:int=numChildren-1;i>=0;i--){
				hdist += getChildAt(i).width + hgap;
			}
			child.x = hdist;
			return super.addChild(child);
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject{
			var index:int = getChildIndex(child);
			var hdist:int = 0;
			for(var i:int = 0;i<index;i++){
				hdist += getChildAt(i).width + hgap;
			}
			for(i = index+1;i<numChildren;i++){
				getChildAt(i).x = hdist;
				hdist += getChildAt(i).width + hgap;
			}
			return super.removeChild(child);
		}
		
	}
}